home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Analysis / Decimation next >
Text File  |  1995-12-28  |  2KB  |  49 lines

  1. #pragma rtGlobals=1
  2.  
  3. // Version 1.01, 05/17/94 -- Used Wave/D instead of Wave in several places.
  4. // Version 1.02, 08/08/94 -- Changed factor to (factor-1) in FDecimate. Previously, one extra point was being averaged.
  5. // Version 1.10, 12/28/95 -- Updated for Igor Pro 3.0. Removed /D which is no longer needed.
  6.  
  7. //    FDecimate(source, dest, factor)
  8. //        See Decimate below for usage.
  9. Function FDecimate(source, destName, factor)
  10.     Wave source
  11.     String destName        // String contains name of dest which may or may not already exist
  12.     Variable factor
  13.     
  14.     Variable numPoints                        // number of points in output wave
  15.     Variable segWidth                            // width of source wave segment
  16.     
  17.     // Clone source so that source and dest can be identical
  18.     Duplicate/O source, decimateTmpSource1
  19.     
  20.     numPoints = numpnts(decimateTmpSource1) / factor
  21.     Duplicate/O decimateTmpSource1, $destName        // keep same precision
  22.     Redimension/N=(numPoints) $destName            // set number of points
  23.     CopyScales decimateTmpSource1, $destName        // X scaling must cover same span
  24.     segWidth = (factor-1)*deltax(decimateTmpSource1)
  25.     
  26.     Wave dw = $destName        // Make compiler understand the next line as a wave assignment
  27.     dw = mean(decimateTmpSource1, x, x+segWidth)
  28.     
  29.     KillWaves/Z decimateTmpSource1
  30. End
  31.  
  32. // Decimate(source, dest, factor)
  33. //    Creates an output wave by averaging every n points of the input wave
  34. //    down to a one point in the output wave.
  35. //    Example:
  36. //        Make/N=1000 wave0; SetScale x 0, 5, wave0
  37. //        wave0 = sin(x) + gnoise(.1)
  38. //        Decimate("wave0", "wave1", 10)
  39. Macro Decimate(sourceName, destName, factor)
  40.     String sourceName
  41.     Prompt sourceName, "Source Wave", popup WaveList("*", ";", "")
  42.     String destName
  43.     Prompt destName, "Destination Wave"
  44.     Variable factor=10
  45.     Prompt factor, "Decimation factor"
  46.     
  47.     PauseUpdate; Silent 1
  48.     FDecimate($sourceName, destName, factor)
  49. End